package br.com.nutriplus.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.nutriplus.entity.Client;

public class ClientJPAController {

	public static void createClient(Client client) {
		EntityManager em = DBAccess.getEntityManager();
		em.getTransaction().begin();
		
		em.persist(client);
		
		em.getTransaction().commit();
	}

	public static List<Client> listClients() {
		List<Client> list = null;

		EntityManager em = DBAccess.getEntityManager();
//		em.getTransaction().begin();

		String psql = "SELECT c FROM Client c";
		Query query = em.createQuery(psql, Client.class);

		list = query.getResultList();
//		em.getTransaction().commit();
		em.close();

		return list;
	}

}
